<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/6/16
 * Time: 18:09
 */
namespace app\account\model;

use app\common\model\Base;
use app\alipay\model\Consume;

class Getdeposit extends Base{


    public function __construct()
    {
        parent::__construct();
//        $sql = "select user.nickname,deposit.id,deposit.uid,deposit.date,deposit.status,deposit.money,user.bank_name,user.bank_number
//            from deposit join user on deposit.uid=user.uid where deposit.status='0'";
 //       $sql="select * from user";
//
//        $date = date("Y-m-d H:i:sa");
//        $sql = "INSERT INTO deposit (uid,date,status,money) VALUES ('oVlguqTtPOZ0','$date','0','1')";
//        $this->result = $this->mysql->insertSQL($sql);    var_dump($this->result);
    }

    public function base(){
        $sql = "select user.nickname,integral.id,integral.uid,integral.date,integral.status,integral.integral,user.bank_name,user.bank_number
            from integral join user on integral.uid=user.uid where integral.status='0'";
        $result = $this->mysql->selectSQLAll($sql);
        
        return  $result?$result:false;
    }

    public function update_status($id){
        $sql = "update deposit set status='1' where id='$id' and status not like '1'";
        $result=$this->mysql->updateSQL($sql);

        return $result;
    }

    public function create_deposit($uid,$deposit){

        if(!$this->check_deposit($uid, $deposit)){
            return false;
        }

        $time = date("Y-m-d H:i:sa");
        $sql = "INSERT INTO integral (uid,date,status,integral) VALUES ('$uid','$time','0','$deposit')";

        return $this->mysql->insertSQL($sql);
    }

    public function check_deposit($uid,$deposit){
        $consume = new Consume();
        if(!$consume->plusIntegral($uid, $deposit)){
            echoJson(0, "积分不够");
        }

        return true;
    }


    
}